<template>
  <div>
    <p></p>

    <el-form
      :model="entity"
      :rules="rules"
      ref="form"
      label-width="100px"
      class="dialog-form"
    >
      <el-row :span="24">
        <el-col :span="12">
          <el-form-item
            style="width: 100%"
            label="部门"
            prop="departmentId"
          >
            <el-input
              disabled
              placeholder="部门标识"
              v-model="entity.departmentId"
              >-->
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item style="width: 100%" label="班次类型" prop="classType">
            <el-select style="width: 100%" v-model="entity.classType">
              <el-option
                :key="10"
                :value="10"
                :label="'10--正常班'"
              ></el-option>
              <el-option :key="20" :value="20" :label="'20--加班'"></el-option>
              <el-option :key="30" :value="30" :label="'30--休班'"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item style="width: 100%" label="班次编码" prop="code">
            <el-input placeholder="班次编码" v-model="entity.code"> </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item style="width: 100%" label="班次名称" prop="name">
            <el-input placeholder="班次名称" v-model="entity.name"> </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item style="width: 100%" label="启用状态" prop="status">
            <el-select style="width: 100%" v-model="entity.status">
              <el-option :key="10" :value="10" :label="'10--草稿'"></el-option>
              <el-option :key="20" :value="20" :label="'20--启用'"></el-option>
              <el-option :key="30" :value="30" :label="'30--禁用'"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!--<el-col :span='12'>-->
        <!--<el-form-item style='width:100%' label='创建时间' prop='createdAt'>-->
        <!--<el-input  placeholder='创建时间' v-model='entity.createdAt'>-->
        <!--</el-input>-->
        <!--</el-form-item>-->
        <!--</el-col>-->
        <!--<el-col :span='12'>-->
        <!--<el-form-item style='width:100%' label='创建人' prop='createdBy'>-->
        <!--<el-input  placeholder='创建人' v-model='entity.createdBy'>-->
        <!--</el-input>-->
        <!--</el-form-item>-->
        <!--</el-col>-->
        <el-col :span="12">
          <el-form-item style="width: 100%" label="修改时间" prop="updatedAt">
            <el-input
              disabled
              placeholder="修改时间"
              v-model="entity.updatedAt"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item style="width: 100%" label="最后修改人" prop="updatedBy">
            <el-input
              disabled
              placeholder="最后修改人"
              v-model="entity.username"
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<style lang="less" scoped>
.merchantLogo .el-upload-dragger {
  img {
    height: 200px !important;
  }
}

.dialog-form {
  .el-radio-group {
    .el-radio {
      display: flex;
      align-items: center;
    }

    label {
      height: 40px;
    }
    .group-text {
      display: inline-block;
      width: 100px;
    }
    .title-text {
      display: inline-block;
      width: 120px;
    }
  }
}
</style>

<script>
const defaultEntity = {
  classMasterId: null, //  班次主表标识
  departmentId: 0, //  部门标识
  classType: 10, //  班次类型
  code: "0", //  班次编码
  name: "0", //  班次名称
  status: 20, //  启用状态
  createdAt: null, //  创建时间
  createdBy: 0, //  创建人
  updatedAt: null, //  最后修改时间
  updatedBy: 0, //  最后修改人
};

export default {
  components: {},
  data() {
    return {
      ppp: "",
      parentId: 0,
      ruleTpl: { when: null, then: null },
      entity: _.cloneDeep(defaultEntity),
      dateRange: [],
      oldProps: [],
      ruleDefs: [],
      isDisabled: false,
      limitTotal: false,
      rules: {
        custNo: [
          { required: true, message: "编号不能为空", trigger: "blur" },
          {
            min: 1,
            max: 6,
            message: "长度在 1 到 6 个字符",
            trigger: "blur",
          },
        ],
        custName: [
          { required: true, message: "名称不能为空", trigger: "blur" },
          {
            min: 1,
            max: 64,
            message: "长度在 1 到 64 个字符",
            trigger: "blur",
          },
        ],
        startOn: [
          {
            required: true,
            message: "请选择开始时间",
            trigger: "blur",
          },
        ],
        merchantId: [
          {
            type: "number",
          },
        ],
        status: [
          {
            type: "number",
            required: true,
            message: "请选择状态",
            trigger: "change",
          },
        ],
        discountType: [
          {
            type: "number",
            required: true,
            message: "请选择优惠类型",
            trigger: "change",
          },
        ],
      },
    };
  },
  methods: {
    getProps(scope) {
      return this.entity.props.filter((p) => p.propScope == scope);
    },
    onRuleDefsLoaded(opts) {
      this.ruleDefs = opts || [];
      this.resetProps();
    },
    onDiscountTypeChange(val) {
      if (val == 3) {
        //次数只能一次
        this.entity.discountValue = 1;
      }
    },
    resetProps() {},
    setValues(vals) {
      this.resetEntity = _.cloneDeep(vals);
      this.entity = _.cloneDeep(this.resetEntity);
    },
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          let params = Object.assign({}, this.entity);

          this.$api.attend.attend.ClassMasterService.save(params).then((rsp) => {
            this.$emit("saved", rsp);
          });
        }
      });
    },
    resetForm() {
      //this.$refs["form"].resetFields();
      this.entity = _.cloneDeep(defaultEntity);
      if (!this.entity.classMasterId) {
        this.entity.createDate = this.$dongxwDict.formatDateZero(new Date());
      }
    },
    init(options) {
      this.resetForm();
      if (options.classMasterId) {
        //console.log(JSON.stringify(this.entity));

        this.$api.attend.attend.ClassMasterService.findById(
          options.classMasterId
        ).then((r) => {
          //console.log(JSON.stringify(r))
          this.entity = r.data;
        });
      } else {
        this.isDisabled = false;
      }
    },
  },
  mounted() {
    this.$on("init", this.init);
    this.$on("submit", this.submitForm);
  },
};
</script>
